--#region
local function PrintOperaName(inputStr)
    if(type(inputStr) ~= type("HHH"))then
        print("传入参数出错!");
    end
    print("-----"..inputStr.."-----");
    print("\n");
end

local function NextLine()
    print("\n");
end
--#endregion


--第二节 字符串操作

PrintOperaName("字符串");
local str_1 = "双引号字符";
local str_2 = '单引号字符';

--一个汉字占3个字节，一个字母一个字节
PrintOperaName("字符串长度");
local s = "ABCDEFG字符串";
print("字符串长度是 "..#s);
NextLine();

PrintOperaName("字符串多行打印");
--用转义字符或者[[ ]]
print("123\n123");
--lua是支持转义字符的
NextLine();

s = [[你好
陆先生
编码
]]
print(s)
NextLine();

PrintOperaName("字符串拼接");
local s_1 = "123";
local s_2 = "456";

print(s_1 .. s_2);
print("123".."456");
print(string.format("我是C#，诞生于%d年",2000));
--[[
    常用占位符
    %d：与数字拼接
    %a：与任何字符拼接
    %s：与字符配对
--]]
NextLine();

PrintOperaName("其他类型转字符串");
local other = true;
print(tostring(other));
local other = nil;
print(tostring(other));
local other = 666;
print(tostring(other));
NextLine();


PrintOperaName("***字符串提供的公共方法***");
local str = "aBcdEFGh"
PrintOperaName("小写转大写");
print(string.upper(str))
PrintOperaName("大写转小写");
print(string.lower(str));
PrintOperaName("反转字符串");
print(string.reverse(str));
PrintOperaName("字符串索引查找");
print(string.find(str,"cdE"));
PrintOperaName("截取字符串");
print(string.sub(str,0,5));
PrintOperaName("字符串重复");
print(string.rep(str,4));
PrintOperaName("字符串修改");
print(string.gsub(str,"aBcd","**--"));
PrintOperaName("字符转ASCII码");
local sss = string.byte("Lua",1)
print(sss);
PrintOperaName("ASCII码转字符");
print(string.char(sss));